package com.smart.cosstarter.model;


import com.smart.cosstarter.constance.DefaultBuckets;
import com.qcloud.cos.model.GetObjectRequest;
import lombok.Data;

import java.io.*;

/**
 * @Author: jj
 * @Date: 2019/8/21 14:59
 * @Version 1.0
 */
@Data
public class DownObjectRequest extends GetObjectRequest {
	public DownObjectRequest(String bucketName, String key, String toPath, String fileName) {
		super(bucketName, key);
		this.toPath = toPath;
		this.fileName = fileName;
	}

	public DownObjectRequest(String bucketName, String key, String toPath) {
		super(bucketName, key);
		this.toPath = toPath;
		this.fileName = key;
	}

	public DownObjectRequest(String key, String toPath) {
		super(DefaultBuckets.bucket, key);
		this.toPath = toPath;
		this.fileName = key;
	}

	public DownObjectRequest(String key) {
		super(DefaultBuckets.bucket, key);
		this.toPath = DefaultBuckets.baseDir;
		this.fileName = key;
	}

	public DownObjectRequest() {
		super(DefaultBuckets.bucket,null);
		this.toPath = DefaultBuckets.baseDir;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	private String toPath;
	private String fileName;

	public String getToPath() {
		return toPath;
	}

	public void setToPath(String toPath) {
		this.toPath = toPath;
	}

	public File getFile() {
		return new File(toPath , fileName);
	}

	public DownloadObject toDownloadObject(){
		return DownloadObjectInstance.getInstance(getFile(),getBucketName(), getKey());
	}
}
